package servlet;

import service.RsService;
import service.impl.RsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/DeleteServlet")
public class DeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String id = request.getParameter("id");
        RsServiceImpl rsService = new RsService();
        int delete = rsService.delete(id);
        if (delete>0){
            request.setAttribute("massgee","<script>alert(\"删除成功!\");</script>");
        }else {
            request.setAttribute("massgee","<script>alert(\"删除失败!\");</script>");
        }
        request.getRequestDispatcher("LoginServlet").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
